﻿using System;
using System.Text;
using mfRCF.Core;
using mfRCF.Core.Extensions;
using mfRCF.Rss;
using Microsoft.SPOT;
using mfXmlSerializer;

namespace mfRCF.NetduinoPlus2.TestApp
{
    public class StateGetCommand : mfRcfCommand
    {
        public StateGetCommand(string httpPath)
            : base(httpPath, new mfGETMethod()) { }


        public override void ExecuteCommand(mfIHttpContext httpContext)
        {
            var state = new State() { Created = DateTime.Now, IsAllOk = true, Message = "...all fine! ;-)" };
            var stateSerializer = new mfXmlTypedSerializer(state.GetType());

            //serialze xml
            using (var xmlStream = stateSerializer.SerializeAsStream(state))
            {
                //write response
                httpContext.Response.ContentType = ContentTypeOut;
                httpContext.Response.StatusCode = enumHttpStatusCode.OK;
                httpContext.Response.WriteStream(xmlStream);
            }

            httpContext.Response.Close();
            Debug.Print(GetType() + " executed, " + Debug.GC(false) + " bytes free");

        }
    }
}
